<?php

	class timer extends service {
		public $__last_timestamp = null;
		static private $instance = NULL;
		
		static function getInstance()
		{
			if (self::$instance == NULL)
			{
				self::$instance = new timer();
			}
			return self::$instance;
		}
		
		public function __construct()
		{
		}

		private function __clone()
		{
		}
		
		function push(){
			$instance = timer::getInstance();
			$instance->__last_timestamp = microtime(TRUE);
			
			return $instance->__last_timestamp;
		}
		
		function pop($__last_timestamp = null){
			$instance = timer::getInstance();
			if (!$__last_timestamp){
				$result = microtime(TRUE) - $instance->__last_timestamp;
			}else{
				$result = microtime(TRUE) - $__last_timestamp;
			}
			
			return $result;
		}
		
		function log($__last_timestamp = null){
			$time_diff = timer::pop($__last_timestamp);
			
			$msg = "".sprintf("%.4f",$time_diff)." sec elasped<br>";
			echo $msg;
		}
		
	}

?>
